home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / mail / listserv / utils / iul2mosaic-gate.pl.Z / iul2mosaic-gate.pl
Encoding:
Perl Script  |  1994-09-07  |  6.4 KB  |  205 lines

  1. #!/usr/local/bin/perl
  2. #I'm posting this CGI script, as a first cut of an interface from Mosaic/Lynx 
  3. #to listproc. Modify the variables in the beginning of the script to suit you,
  4. #and put it in your cgi-bin directory on your web server. Create an HREF in
  5. #the home page, to the script, and you should be ready to go.
  6. #
  7. #You also need to have IUL ported to your web server.
  8. #
  9. #Any ideas and improvements are very welcome (pthomsen@netcom.com).
  10. #
  11. #For V2, I'm thinking of adding an administrative page, and more commands.
  12. #
  13. # Copyright (c) 1994 Per Reedtz Thomsen (pthomsen@netcom.com).
  14. #
  15. #
  16. # Iul-gate is free software; you can redistribute it and/or modify
  17. # it as long as you do not in any way modify the Copyright notices 
  18. # in this file.
  19. #
  20. # Iul-gate is distributed in the hope that it will be useful,
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23. # GNU General Public License for more details.
  24. #
  25. # No warranty is given for the useability of this software for any 
  26. # purposes whatsoever. If it's useful to you, good; if not, tough!
  27. #
  28. # Author: pthomsen@netcom.com (Per Reedtz Thomsen)
  29. #
  30. # Major contributions (and polishing): Hubert Shaw
  31. # History:
  32. #        09/08/94    pthomsen    Genericized
  33. #               09/08/94        hshaw           Fixed footers for 'gets'
  34. #               09/07/94        hshaw           Fixed to work on hps737
  35. #               08/29/94        pthomsen    Created.
  36. #
  37.  
  38. format top =
  39. <pre>Name                                    Size   Description</pre><hr>
  40. .
  41. format STDOUT =
  42. <pre>@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  @>>>>>>   @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< </pre>
  43. $ref,$hack,$name,                            $size,    $description
  44. .
  45.  
  46. # Set up the query received from httpd.
  47. @querya    = @ARGV;
  48.  
  49. # ================================================
  50. # Modify these 6 variables, to set up your config.
  51. # ================================================
  52. $lsadmin   = "Per Thomsen (pthomsen@us.oracle.com)";  # The ListServ administrator
  53. $cgiadmin  = "Foo Bar (foobar@us.oracle.com)";        # The cgi (or http) administrator
  54. $basetitle = "Power Products Division Archives";      # The beginning of the title string
  55. $iul       = "/usr/local/etc/httpd/bin/iul";          # Full path of the IUL executable
  56. $host      = "gravity";                               # The host to connect to
  57. $footer    = "<hr>\n<ADDRESS>The 'oracle4u' List Server is maintained by $lsadmin</ADDRESS>\n";
  58.                                                       # This will be at the bottom of every page
  59. $bmapoff   = "   ";
  60.  
  61. if (@querya <= 1)
  62. {
  63.   $query     = "index";
  64.   $keywd     = "index";
  65.   $idxpath   = "ListServ";
  66.   # =======================================================================
  67.   # The $introtext variable can also be edited, to say whatever you need...
  68.   # =======================================================================
  69.   $introtext = "<h1>$basetitle</h1><p>
  70. This HTML page gives access to the 'oracle4u' List Server archives. These archives are also available via email.<p>
  71. <ADDRESS>Contact $lsadmin for more information on List Server.</ADDRESS><p>
  72. <ADDRESS>Contact $cgiadmin if you have problems with this interface.</ADDRESS><hr>";
  73. }
  74. else
  75. {
  76.   $query     = join(" ", @querya);
  77.   $keywd     = @querya[0];
  78.   $idxpath   = @querya[1];
  79.   $introtext = "";
  80. }
  81.  
  82. if ($keywd eq "get")
  83. {
  84.   $title = "<title>$basetitle ($idxpath): @querya[2]</title>\n";
  85. }
  86. else
  87. {
  88.   $title = "<title>$basetitle ($idxpath)</title>\n";
  89. }
  90.  
  91. # Name of files containing IUL input/output
  92. $cmdfile = "/tmp/iulcmd.$$";
  93. $outfile = "/tmp/iulout.$$";
  94.  
  95. # Create a file full of commands to be run by IUL
  96. open(COMMANDS, "> $cmdfile") || die "Can't open temp command file\n";
  97. print COMMANDS "\n$query > $outfile\nquit\n";
  98. close COMMANDS;
  99.  
  100. # Run IUL with the command file
  101. open(IUL, "$iul $host < $cmdfile |") || die "IUL didn't run\n";
  102. while (<IUL>) {}
  103. close IUL;
  104. unlink $cmdfile;
  105.  
  106.  
  107. open(IUL, "< $outfile") || die "cannot retrieve IUL output\n";
  108.  
  109. # Print out HTML id
  110. print "Content-type: text/html\n";
  111. print "\n";
  112. print $title;
  113. print $introtext;
  114.  
  115. if ($keywd eq "index")
  116. {
  117.   while (<IUL>)
  118.   {
  119.     if (/^Archive:/)
  120.     { # handle archives
  121.       $archname = $_;
  122.       $archname =~ s/.*path: (.*)\).*/\1/;
  123.       chop $archname;
  124.       while (<IUL>)
  125.       {
  126.     last if (/^$/);              # No more files in this archive
  127.         chop $_;
  128.         if (/.*part.*bytes.*/)
  129.         { # handle files
  130.           if (/.*--.*/)
  131.           {
  132.             ($fileinfo,$filedes) = split("--");
  133.           }
  134.           else
  135.           {
  136.             $fileinfo = $_;
  137.             $filedes  = "(no description available)";
  138.           }
  139.           local($filename,$sizeinfo) = ($fileinfo,$fileinfo);
  140.           $filename =~ s/[ ]*(.*)[ ]*\(.*\).*/\1/;
  141.           chop $filename;
  142.           $ref      =  "<img align=bottom src=/icons/text.xbm alt=\"   \"> <a href=iul-gate.pl?get+$archname+$filename";
  143.           $hack     =  ">";
  144.           $name     =  $filename . "</a>";
  145.           $sizeinfo =~ s/.*\((.*)\).*/\1/;
  146.           $sizeinfo =~ s/{parts|,|bytes}//;
  147.           @sizes = split(' ', $sizeinfo);
  148.           for ($pt = @sizes[0], $size = 0; @sizes;)
  149.           {
  150.             shift @sizes;
  151.             $size += @sizes[0];
  152.           }
  153.           $description = $filedes;
  154.           $description =~ s/^[ \t]*(.*)/\1/;
  155.           write;
  156.         }
  157.         else
  158.         { # handle extra lines of description
  159.           chop;
  160.           $ref   = "<!-";
  161.           $hack  = ">";
  162.           $name  = "<!->";
  163.           $size  = "";
  164.           $pt    = "";
  165.           $description = $_;
  166.           $description =~ s/^[ \t]*(.*)/\1/;
  167.           $description = $bmapoff . $description;
  168.           write;
  169.         }
  170.       }
  171.     }
  172.     elsif (/^Subarchive:/)
  173.     { # handle subarchives
  174.       local($archname,$archpath) = ($_,$_);
  175.       $archname =~ s/^Subarchive: (.*)[ ]\(.*\).*/\1/;
  176.       chop $archname;
  177.       $archpath =~ s/.*\(path: (.*)\).*/\1/;
  178.       chop $archpath;
  179.       $ref   = "<img align=bottom src=/icons/menu.xbm alt=\"   \"> <a href=iul-gate.pl?index+$archpath";
  180.       $hack  = ">";
  181.       $name  = $archname . "</a>";
  182.       $size  = "";
  183.       $pt    = "";
  184.       $description = "[Subarchive - $archpath]";
  185.       write;
  186.     }
  187.   }
  188. }
  189. elsif ($keywd eq "get")
  190. {
  191.   print "<pre>\n";
  192.   while (<IUL>)
  193.   {
  194.     print;
  195.   }
  196.   print "</pre>\n";
  197. }
  198.  
  199. # Print contact info.
  200. print $footer;
  201.  
  202. close  IUL;
  203. unlink $outfile;
  204.